#include "mytreewidgetitem.h"
#include "ui_mytreewidgetitem.h"
#include <QFile>

MyTreeWidgetItem::MyTreeWidgetItem(struct st_treeItem data,QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MyTreeWidgetItem)
{
    ui->setupUi(this);
    int borderWidth = 10; // 边框的宽度
    cv::Scalar borderColor(0, 0, 0, 255);

    switch(data.type){
    case TI_FRIEND:{
        ui->stackedWidget->setCurrentWidget(ui->page_friend);
        QString hname = QString("%1.png").arg(data.fdata.dd_num);
        QString head_url = QString("%1/%2").arg(PATH_IMG).arg(hname);
        ui->le_head->setPixmap(RoundBorderPixmap(downLoadFromUrl(head_url),borderWidth,borderColor));
        ui->le_nick->setText(data.fdata.nick);
        if(data.fdata.status == 0){
            ui->le_status->setPixmap(QPixmap(":/prefix2/software/offline.png"));
        }
        else{
           ui->le_status->setPixmap(QPixmap(":/prefix2/software/online.png"));
        }

    }
        break;
    case TI_GROUP:{
        ui->stackedWidget->setCurrentWidget(ui->page_group);
        QString gname = QString("%1.png").arg(data.gdata.gid);
        QString gicon_url = QString("%1/%2").arg(PATH_IMG).arg(gname);
        ui->le_gicon->setPixmap(RoundBorderPixmap(downLoadFromUrl(gicon_url),borderWidth,borderColor));
        ui->le_gname->setText(data.gdata.gname);
    }
        break;
    }

    connect(this,&MyTreeWidgetItem::sig_noread_flag,this,[=](int flag){
        switch(flag){
            case 0:ui->lab_noread->setPixmap(QPixmap(":/prefix2/software/noread_2.png"));
                break;
            case 1:ui->lab_noread->clear();
                break;
            case 2:ui->le_nonread->setPixmap(QPixmap(":/prefix2/software/noread_2.png"));
                break;
            case 3:ui->le_nonread->clear();
                break;

        }
    });

}

MyTreeWidgetItem::~MyTreeWidgetItem()
{
    delete ui;
}

int MyTreeWidgetItem::getNoread_flag() const
{
    return noread_flag;
}

void MyTreeWidgetItem::setNoread_flag(int newNoread_flag)
{
    noread_flag = newNoread_flag;
}

